home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / client < prev    next >
Text File  |  1995-03-31  |  3KB  |  142 lines

  1. Article 2862 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!news.cs.indiana.edu!julius.cs.uiuc.edu!usc!apple!rutgers!netnews.upenn.edu!hoford@sequoia.upenn.edu
  3. From: hoford@sequoia.upenn.edu (John Hoford)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: hp48 as a client?
  6. Message-ID: <34588@netnews.upenn.edu>
  7. Date: 11 Dec 90 22:30:54 GMT
  8. Sender: news@netnews.upenn.edu
  9. Organization: CIRC,Radiology,U. of Pennsylvania
  10. Lines: 128
  11.  
  12. This c progam allows you to type hp commands
  13. on your unix machine.
  14.  
  15.  
  16. ------ cut here --------
  17. /*
  18.   This progams runs on a sun4 os4.1 and should run 
  19.   on most unix boxes.
  20.   It runs kermit in background and sends the commands you
  21.   type in to the hp48 by appending them to "remote host".
  22.  
  23.   All commands should be upper case.
  24.   You can place multiple commands on a line ( 10 2 / ).
  25.   It responds by outputing the stack.
  26.   You can also type the dir command which runs "remote dir"
  27.   and done which quits
  28.  
  29.   
  30.   configure your .kermrc to your "line" and "baud" and
  31.   run progam.
  32.  
  33.   please send improvements to hoford@gynko.circ.upenn.edu 
  34.  
  35. */
  36.  
  37.  
  38.  
  39.  
  40. #include<stdio.h>
  41. #include<signal.h>
  42.  
  43. #define TRUE 1
  44.  
  45. int   reap_kermit();
  46. char  str[80];
  47. char  cmd_str[30];
  48.  
  49.  
  50. main()
  51. {
  52.   int kin[2];
  53.   int pid;
  54.   int head_len;
  55.   int i;
  56.   
  57.   strcpy(str,"remote host ");
  58.   head_len =  strlen(str);
  59.   pipe(kin);               /* make a pipe */
  60.   
  61.   signal(SIGCHLD,kermit_end);  /* when child exits call kermit_end func */
  62.  
  63.  
  64.   if ((pid = fork()) == -1)
  65.     {
  66.       fprintf(stderr,"erro cannot fork\n");
  67.       exit(1);
  68.     }
  69.  
  70.  
  71.   if (pid==0)         /* in child child*/
  72.     {
  73.       close(0);
  74.       dup(kin[0]);
  75.       
  76.       execl("/usr/local/bin/kermit",NULL); /*call kermit
  77.       fprintf(stderr,"could not execl\n"); /* shold not reach hear */
  78.       exit(2);
  79.     }
  80.   
  81.   /*-------- in parent---------- */
  82.   
  83.   while(TRUE)                            /* loop forever       */
  84.     {
  85.       gets(cmd_str);                     /* read cmd line      */
  86.  
  87.       if (strcmp("done",cmd_str))        /* if cmd is not done */
  88.     {
  89.       if (strcmp("dir",cmd_str))     /* if cmd is not dir  */
  90.         {
  91.           if (strlen(cmd_str) != 0)
  92.         {
  93.           cmd_str[strlen(cmd_str)] = '\n';  /* append "\n" */
  94.           cmd_str[strlen(cmd_str)+1] = (char) 0;
  95.  
  96.           for(i=0;i<strlen(cmd_str);i++)  /* remove after \n */
  97.             if (cmd_str[i] == '\n') 
  98.               {
  99.             cmd_str[i+1] = 0;
  100.             break;
  101.               }
  102.  
  103.  
  104.           strcpy(&(str[head_len]),cmd_str); /* apend to rem host */
  105.           write(kin[1],str,strlen(str));    /* write to stdin of */
  106.                                             /* kermit            */
  107.         }                                   
  108.         }
  109.       else          /* if dir  run remote dir*/
  110.         {
  111.           write(kin[1],"remote dir\n",strlen("remote dir\n"));
  112.         }
  113.     }
  114.       else  /* if done */
  115.     {
  116.       printf("kill kermit \n");
  117.       write(kin[1],"bye\n",4);  /* shut down hp server */
  118.       write(kin[1],"quit\n",5); /* quit kermit */
  119.       sleep(2);                 /* wait awhile */
  120.       kill(pid,SIGTERM);        /* make shure kill again */
  121.       exit(1);                  /* done */
  122.     }
  123.       
  124.     } 
  125.   
  126. }
  127.  
  128.  
  129. kermit_end() /* if died print the string that killed  */
  130. {
  131.   printf("kermit died str = %s\n",str);
  132.   exit();
  133.   
  134. }
  135. --
  136. Steven D. Kugelmass, Ph.D.
  137. Director, Computer Science
  138. Cardiothoracic Imaging Research Center
  139. Department of Radiology
  140.  
  141.  
  142.